<?php
/*
 * @Author: your name
 * @Date: 2020-06-05 17:32:41
 * @LastEditTime: 2020-12-28 10:15:25
 * @LastEditors: Please set LastEditors
 * @Description: 业务系统管理
 * @FilePath: /special/application/adminapiv3/controller/asset_manage/ServiceProviderService.php
 */

namespace app\adminapiv3\controller\asset_manage\service_provider;

use app\adminapiv3\controller\BaseController;
use app\adminapiv3\service\asset_manage\service_provider\ServiceService;
use think\Request;

class ServiceController extends BaseController
{
    /**
     * 列表
    */
    public function list(Request $request)
    {
        //接收参数
        $params = $request->only([
            'name','status','type','description'
        ],'get');

        $server = new ServiceService();
        $list = $server->list($params);

        return $this->jsonOutPut($list);
    }

    /**
     * @name 添加
     * @author wx
     * @date 2019/10/24 10:39
     */
    public function add(Request $request)
    {
        //接收参数
        $params = $request->only([
            'name','contact','position','phone','start_time','is_local','address','content','description','type'
        ],'post');
        $this->validate($params,'Service.add');

        $type = $params['type'];//服务商类型

        unset($params['type']);

        $server = new ServiceService();
        $server->add($params, $type);

        return $this->jsonOutPut();
    }

    /**
     * @name 服务商详情
     * @author wx
     * @date 2019/10/24 10:54
     */
    public function detail(Request $request)
    {
        $params = $request->only([
            'id'
        ],'post');
        $this->validate($params,'Service.detail');

        $server = new ServiceService();
        $info = $server->detail($params['id']);

        return $this->jsonOutPut($info);
    }

    /**
     * @name 修改
     * @author wx
     * @date 2019/10/24 13:34
     */
    public function modify(Request $request)
    {
        //接收参数
        $params = $request->only([
            'id','name','contact','position','phone','start_time','is_local','address','content','description','type'
        ],'post');
        $this->validate($params,'Service.modify');

        $serviceId = $params['id'];
        $type = $params['type'];

        unset($params['type']);

        $server = new ServiceService();
        $server->modify($serviceId, $params, $type);

        return $this->jsonOutPut();
    }

    /**
     * @name 删除
     * @author wx
     * @date 2019/10/24 14:00
     */
    public function del(Request $request)
    {
        //接收参数
        $params = $request->only([
            'service_id'
        ],'post');
        $this->validate($params,'Service.del');

        $server = new ServiceService();
        $server->del($params['service_id']);

        return $this->jsonOutPut();
    }

    /**
     * @name 服务商服务历史
     * @author wx
     * @date 2019/10/24 14:09
     */
    public function serviceHistory(Request $request)
    {
        $params = $request->only([
            'service_id'
        ],'get');
        $this->validate($params,'Service.del');

        $server = new ServiceService();
        $list = $server->serviceHistory($params['service_id']);

        return $this->jsonOutPut($list);
    }

    /**
     * @name 续约更新
     * @author wx
     * @date 2019/10/24 14:13
     */
    public function updateService(Request $request)
    {
        $params = $request->only([
            'service_id','end_time','content'
        ],'post');
        $this->validate($params,'Service.updateService');

        $serviceId = $params['service_id'];
        $endTime = $params['end_time'];
        $content = $params['content'];

        $server = new ServiceService();
        $server->updateService($serviceId, $endTime, $content);

        return $this->jsonOutPut();
    }

    /**
     * @name 终止合作
     * @param Request $request
     * @return \think\response\Json
     * @author wx
     * @date 2020/10/20 16:10
     */
    public function endContract(Request $request)
    {
        $params = $request->only([
            'service_id','end_reason','end_reason_description'
        ],'post');
        $this->validate($params,'Service.endContract');

        $serviceId = $params['service_id'];
        $endReason = $params['end_reason'];
        $endReasonDescription = isset($params['end_reason_description']) ? $params['end_reason_description'] : '';


        $server = new ServiceService();
        $server->endContract($serviceId, $endReason, $endReasonDescription);

        return $this->jsonOutPut();
    }

}